require 'ajax_scaffold'

class User < ActiveRecord::Base
  has_many :tasks 
  
  validates_presence_of :username,:password
  
  validates_uniqueness_of :username
  validates_confirmation_of :password
  #validates_format_of :username, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/
  
  # Returns the User object that matches the supplied +username+ and +password+
  # arguments, or returns +nil+ if no match is found.
  def self.authenticate(username, password)
    find_by_username_and_password(username, password)
  end
  
  # return a simple username
  def short_username
    index = username.index('@')
    if index == nil
      username
    else
      username.slice(0...index)
    end
  end
end
